package com.hand.demo.app.service.impl;


import java.io.IOException;

import org.codehaus.jackson.map.ObjectMapper;
import org.hzero.boot.imported.app.service.IDoImportService;
import org.hzero.boot.imported.infra.validator.annotation.ImportService;
import org.springframework.beans.factory.annotation.Autowired;

import com.hand.demo.domain.entity.Example;
import com.hand.demo.domain.repository.ExampleRepository;

/**
 * @author yufan.yao@hand-china.com //
 */
@ImportService(templateCode = "HAIP.SENSITIVE_WORDS")
public class DemoClient implements IDoImportService {
    @Autowired(required = false)
    private ObjectMapper objectMapper;
    @Autowired
    private ExampleRepository exampleRepository;

    @Override
    public Boolean doImport(String data) {
        Example example = new Example();
        try {
            objectMapper.readValue(data, Example.class);
        } catch (IOException e) {
            // 失败
            return false;
        }
        if (example.getName()!="李李"){
            exampleRepository.insert(example);
        }
        return true;
    }
}
